import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

// $store中包括user、settings模块，请勿重名
import { $gc } from 'gc-starter-ui-plus'

const modulesFiles = require.context('./modules', true, /\.js$/)

// 引入modules
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  const value = modulesFiles(modulePath)
  modules[moduleName] = value.default
  return modules
}, {})

const store = new Vuex.Store({
  modules: {
    ...$gc.store,
    ...modules
  }
})

export default store
